/**
 * @see [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-file.html#wxdownloadfileobject)
 * @param url [string] 下载资源的 url
 * @param header [wx.RequestHeader] HTTP 请求 Header，header 中不能设置 Referers
 */
export default function download_file(url: string, header?: wx.RequestHeader) {
	return new Promise<{
		msg: wx.TempFileResponse;
		success: boolean;
	}>((resolve) => {
		wx.downloadFile({
			header,
			url,
			success(res) {
				resolve({
					msg: res,
					success: true
				});
			},
			fail(res) {
				resolve({
					msg: res,
					success: false
				});
			}
		});
	});
}
